import * as types from "./mutation-types";
import Api from "api/api";
const state = {
  TempSkinList:[],//栏目模板风格（首页列表数据）
  TempUpload:"",//上传栏目模板文件
  TempDel:"",//删除模板文件
  TempChild:[],//显示子文件和子文件夹
  TempContent:"",//写入模板文件内容
  TempQuery:"",//点击模板管理，获取所有的模板文件名
  TempReadFile:"",//读取模板文件内容
  FileDel:"",//删除文件
};
const getters = {
  TempSkinList: state => state.TempSkinList,
  TempUpload: state => state.TempUpload,
  TempDel: state => state.TempDel,
  TempChild: state => state.TempChild,
  TempContent: state => state.TempContent,
  TempQuery: state => state.TempQuery,
  TempReadFile: state => state.TempReadFile,
  FileDel: state => state.FileDel,
};
const actions = {
  //栏目模板风格
  queryAppTemplateSkinUsingGETS({ commit }, param) {
    return Api.queryAppTemplateSkinUsingGET(param).then(ret => {
      commit(types.UPDATE_TEMP_SKIN_LIST, ret.data);
      return ret;
    });
  },
  //上传栏目模板文件
  uploadUsingPOSTS({ commit }, param) {
    return Api.uploadUsingPOST(param).then(ret => {
      commit(types.UPDATE_TEMP_UPLOAD_LIST, ret.data);
      return ret;
    });
  },
  //删除文件
  deleteFileUsingDELETES({ commit }, param) {
    return Api.deleteFileUsingPOST(param).then(ret => {
      commit(types.UPDATE_FILE_DEL_LIST, ret.data);
      return ret;
    });
  },
  //删除模板
  deleteTemplateFileUsingPOSTS({ commit }, param) {
    return Api.deleteTemplateFileUsingPOST(param).then(ret => {
      commit(types.UPDATE_TEMP_DEL_LIST, ret.data);
      return ret;
    });
  },
  //显示子文件和子文件夹
  showChildFileAndFolderUsingGETS({ commit }, param) {
    return Api.showChildFileAndFolderUsingGET(param).then(ret => {
      commit(types.UPDATE_TEMP_CHILD_LIST, ret.data);
      return ret;
    });
  },
  //写入模板文件内容
  writeFileContentUsingPOSTS({ commit }, param) {
    return Api.writeFileContentUsingPOST(param).then(ret => {
      commit(types.UPDATE_TEMP_CONTENT_LIST, ret.data);
      return ret;
    });
  },
  //点击模板管理，获取所有的模板文件名
  queryTemplateSkinUsingGETS({ commit }, param) {
    return Api.queryTemplateSkinUsingGET(param).then(ret => {
      commit(types.UPDATE_TEMP_QUERY_LIST, ret.data);
      return ret;
    });
  },
  //读取模板文件内容
  readFileContentUsingGETS({ commit }, param) {
    return Api.readFileContentUsingGET(param).then(ret => {
      commit(types.UPDATE_TEMP_READ_LIST, ret.data);
      return ret;
    });
  },
};
const mutations = {
  [types.UPDATE_TEMP_SKIN_LIST](state, payload) {
    state.TempSkinList = payload;
  },
  [types.UPDATE_TEMP_UPLOAD_LIST](state, payload) {
    state.TempUpload = payload;
  },
  [types.UPDATE_TEMP_DEL_LIST](state, payload) {
    state.TempDel = payload;
  },
  [types.UPDATE_TEMP_CHILD_LIST](state, payload) {
    state.TempChild = payload;
  },
  [types.UPDATE_TEMP_CONTENT_LIST](state, payload) {
    state.TempContent = payload;
  },
  [types.UPDATE_TEMP_QUERY_LIST](state, payload) {
    state.TempQuery = payload;
  },
  [types.UPDATE_TEMP_READ_LIST](state, payload) {
    state.TempReadFile = payload;
  },
  [types.UPDATE_FILE_DEL_LIST](state, payload) {
    state.FileDel = payload;
  },
};
export default {
  state,
  getters,
  actions,
  mutations
};
